﻿using movie.tool.module.update.service;
using System.ComponentModel;
using System.Windows;
using System.Windows.Navigation;

namespace movie.tool
{

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window,INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void SendPropertyChanged(string propetyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propetyName));
            }
        }

        private string currentPage;
        public string CurrentPage
        {
            get => currentPage;
            set
            {
                currentPage = value;
                SendPropertyChanged(nameof(CurrentPage));
            }
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (movie_tool.App.APP_FOR_TEST)
            {
                Title = Title + "-测试版本";
            }
            //MainWindow.ShowPage("module/film/ui/MovieDetailPage.xaml");
            bool update = await UpdateManager.Instance.UpdateCheck();
            if (update)
            {
                ShowPage("/module/update/ui/UpdateUI.xaml");
            }
            else
            {
                ShowLoginPage();
            }
            
            main.Navigated += Main_Navigated;
        }

        private void Main_Navigated(object sender, NavigationEventArgs e)
        {
            if (main.CanGoBack)
            {
                main.RemoveBackEntry();
            }
        }

        public static void ShowPage(string page)
        {
            MainWindow mw = Application.Current.MainWindow as MainWindow;
            if(mw != null)
            {
                mw.CurrentPage = page;
            }
        }
        public static void ShowLoginPage()
        {
            ShowPage("/module/login/LoginPage.xaml");
        }
    }
}
